/*
 * SendStatus.java
 *
 * Created on May 6, 2009, 2:48 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package im.resources;

import im.general.AbstractListenBehaviour;
import im.general.Config;
import im.messages.BaseMessage;
import im.messages.MessagePayload;
import im.resources.ResourceStatus;
import im.node.MobileNodeAgent;
import jade.core.AID;
import jade.core.ContainerID;
import jade.core.behaviours.CyclicBehaviour;
import jade.domain.JADEAgentManagement.WhereIsAgentAction;
import jade.lang.acl.ACLMessage;
import java.io.IOException;

/**
 *
 * @author bluejack
 */
public class ResourceListen extends AbstractListenBehaviour {
    
    MobileNodeAgent rm = null;
    /** Creates a new instance of SendStatus */
    public ResourceListen(MobileNodeAgent rm) {
        this.rm = rm;
    }
    

public void moveToAgent(AID agent) {
    jade.core.ContainerID c = new ContainerID();
    System.out.println("moving to: " +agent.getName());
}



public void sendStatus (ACLMessage reply) {
            reply.setPerformative(ACLMessage.INFORM);
            //reply.setContent(Float.toString(rm.getStatus()));
            
            MessagePayload payload = new MessagePayload(Config.STATUS, ((MobileNodeAgent)myAgent).getStatus());
            //ResourceStatus rs = new ResourceStatus(rm);
            
            System.out.println(myAgent.getName() + " sending status to " + reply.getAllReceiver().toString());
            try {
                //reply.setContent(rs);
                reply.setContentObject(payload);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            myAgent.send(reply);
}

    protected void manageMessage(ACLMessage msg) {
        sendStatus(msg.createReply());
    }

    @Override
    protected void handleMessage(ACLMessage msg) {
        throw new UnsupportedOperationException("Not supported yet.");
    }



}
